//       https://ac.nowcoder.com/acm/contest/11217/I






#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        b[i] = i;
    }

    int ans = 0;
    do
    {
        bool flag = true;
        for (int i = 1; i <= n; ++i)
        {
            if (b[i] <= b[a[i]]) continue;
            flag = false;
            break;
        }
        ans += flag;
    } while (next_permutation(b.begin() + 1, b.end()));

    cout << ans;
    return 0;
}